package org.example.infrastructure.repository.remote;

import lombok.RequiredArgsConstructor;
import org.example.domain.model.entity.url.resp.QueryGroupByCountResp;
import org.example.infrastructure.persistence.remote.RemoteUrlShortenerPersistence;
import org.example.web.exception.ServerException;
import org.example.web.result.BaseSuccessCode;
import org.example.web.result.ResultInfo;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

@Repository
@RequiredArgsConstructor
public class RemoteUrlShortenerRepository {
    private final RemoteUrlShortenerPersistence remoteUrlShortenerPersistence;

    public List<QueryGroupByCountResp> queryGroupByCount(List<String> gidList){
        ResultInfo<List<QueryGroupByCountResp>> resultInfo = remoteUrlShortenerPersistence.queryGroupByCount(gidList);
        if (!Objects.equals(resultInfo.getStatus(), BaseSuccessCode.SUCCESSFUL_OPERATION.code())){
            throw new ServerException("查询分组失败！");
        }
        return resultInfo.getData();
    }
}
